/**
 * 
 * url:网络请求的url
 * params:发送的数据
 * success:成功的回调函数
 * fail：失败的回调
 * message:loading的提示信息（可选项）
 */
// const baseUrl = "https://www.saramei.com/gd/"
// const baseUrl = "http://192.168.5.6:8080/wx"
const baseUrl = "http://localhost:10086/lg"
const imgUrl="http://47.104.237.150:8093/images/"

const getOpenIAPI = "/wechat/query/openId" //获取openId
const visitorApplyAPI = "/visitor/add"; //访客申请
const visitorListAPI = "/visitor/list"; //访客申请
const visitorApproveAPI = "/visitor/approve"; //访客申请
const meetingApplyAPI = "/meeting/apply/add"; //会议申请
const meetingListAPI = "/meeting/apply/List"; //会议列表
const meetingCancelAPI = "/meeting/apply/cancel"; //取消会议
const problemAddAPI = "/problem/add";
const problemListAPI = "/problem/list";
const meetingRoomListAPI = "/meeting/apply/meetingroom"; //会议室列表
const memRegisterAPI = "/member/register"; //会员注册

function httpRequest(url, data = {}, method = 'post') {
  url = baseUrl + url;
  wx.showToast({
    title: '提交中', // 提示的内容
    icon: 'loading', // 图标，可以是 'success'、'loading' 等
    duration: 1000, // 提示的显示时间（单位：毫秒）
    mask: true // 是否显示透明蒙层，防止触摸穿透
  });
  return new Promise((resolve, reject) => {
    wx.request({
      url: url,
      data: data,
      method: method,
      header: {
        'content-type': 'application/json' // 设置请求的 header
      },
      success: function (res) {
        if (res.statusCode === 200) {
          resolve(res.data); // 请求成功，返回数据
        } else {
          reject({
            code: res.statusCode,
            message: '请求失败'
          }); // 请求失败
        }
      },
      fail: function (error) {
        reject({
          code: -1,
          message: '网络错误'
        }); // 网络错误
      }
    });
  });
}
module.exports = {
  getOpenIAPI: getOpenIAPI,
  httpRequest: httpRequest,
  visitorApplyAPI: visitorApplyAPI,
  problemAddAPI: problemAddAPI,
  problemListAPI: problemListAPI,
  meetingRoomListAPI: meetingRoomListAPI,
  meetingApplyAPI: meetingApplyAPI,
  meetingListAPI: meetingListAPI,
  meetingCancelAPI: meetingCancelAPI,
  visitorListAPI: visitorListAPI,
  memRegisterAPI: memRegisterAPI,
  imgUrl: imgUrl
}